home *** CD-ROM | disk | FTP | other *** search
- /* formruns.c - form initial runs from input file */
- #include "stdio.h"
- #include "cminor.h"
- #include "merge1.h"
-
- extern int (*compfun) () ; /* address of compare function */
-
- FILE *do_open() ; /* opens file & checks for errors */
-
- int formruns(fromfile,scr,tofile)
- char fromfile[] ; /* input file name */
- char scr[] ; /* pointers to lines of text */
- char tofile[] ; /* put output here */
- {
- int irun ,nrec , ret ;
- char sarea[SSIZE ] ; /* storage area for text lines */
- char *p[ MAX_REC ] ; /* pointers to lines of text */
- FILE *infile ; /* input file */
- char oname[68] ; /* build scratch file names here */
-
- infile = do_open(fromfile,"r") ; /* open input file */
-
- initfill(infile) ; /* initialize for fillarea */
- irun = 0 ;
- do
- { /* read text file into storage area */
- ret = fillarea(sarea,SSIZE,p,MAX_REC,&nrec,infile) ;
- memsort(p,nrec,compfun) ; /* sort using compare function */
- /* now write out sorted lines */
- if( (ret != AT_EOF) || (irun > 0) )
- mkname(oname,tofile) ; /* use scratch file */
- else strcmp(oname,tofile) ; /* one run - use output file */
- outfile(p,nrec,oname) ;
- irun = irun + 1 ;
- } while( ret != AT_EOF ) ;
-
- do_close(infile,fromfile) ;
- return( irun ) ;
- }
-
-
-